from datetime import datetime, timedelta

import akshare as ak

import akshare as ak
class TradeDateUtils:
    def __init__(self):
        self.tool_trade_date_hist_sina_df = ak.tool_trade_date_hist_sina()
        self.get_trade_date_list()

    def get_trade_date_list(self):
        self.tool_trade_date_hist_sina_df['trade_date'] = self.tool_trade_date_hist_sina_df['trade_date'].astype(str)
        self.dl = self.tool_trade_date_hist_sina_df['trade_date'].tolist()
        return self.dl

    #返回指定交易日的前一天
    def get_pre_trade_date(self,trade_date):
        index = self.dl.index(trade_date)
        return self.dl[index - 1]
    #返回指定交易日的后一天
    def get_next_trade_date(self,trade_date):
        index = self.dl.index(trade_date)
        return self.dl[index + 1]
    def get_today_str(self):

        return datetime.now().strftime('%Y-%m-%d')
    def get_today_tomorrow(self,start_date):
        tomorrow = self.get_next_trade_date(start_date)
        return [start_date, tomorrow]

    def get_today_yesterday(self,start_date):
        tomorrow = self.get_pre_trade_date(start_date)
        return [tomorrow, start_date]
